const DBUtils = require("../database/DBUtils");
const moment = require("moment");
const { uuid } = require("../utils.js");

module.exports.gameEndSave = async function (room, winuser,gameid,windesc) {
  let createtime =  moment().format("YYYY-MM-DD HH:mm:ss");
  console.log("winuser",winuser);
  for (let i = 0; i < room.users.length; i++) {
    let user = room.users[i];
    console.log("user",user);
    let r = await DBUtils.query("insert into gamerecord (id,userid,score,createdtime,winuser,windesc,winnickname,winheadimg,status,nickname,headimg,roomid,gameid) values (?,?,?,?,?,?,?,?,?,?,?,?,?)", [
      uuid(),
      user.id,
      winuser==user.id?10:-10,
      createtime,
      winuser.id,
      windesc,
      winuser.nickname,
      winuser.headimg,
      winuser==user.id?1:2,
      user.nickname,
      user.headimg,
      room.id,
      gameid
    ])
  }
}